package gofish.json;

/**
 * JsonArrayElement(s) are ultimately used as leaf nodes in JsonArray objects.
 * @author Matt Lauber
 *
 */
public class JsonArrayElement extends AbstractJson {

	/**
	 * value is of the generic type Object so it can hold Boolean, String,
	 * Integer, Double, Character, an AbsractCompositeJson, or a String
	 * representation of null.
	 */
	private Object value;
	
	/**
	 * There is one constructor for each of the classes mentioned above.
	 * Each one sets up value so that, when toString() is called, value
	 * will be displayed in appropriate JSON format.
	 * @param v : will be assigned to the value instance variable.
	 */
	public JsonArrayElement(String v) {
		this.value = "\"" + v + "\"";
	}
	
	public JsonArrayElement(char v) {
		this.value = "\"" + String.valueOf(v) + "\"";
	}
	
	public JsonArrayElement(int v) {
		this.value = new Integer(v);
	}
	
	public JsonArrayElement(double v) {
		this.value = new Double(v);
	}
	
	public JsonArrayElement(boolean v) {
		this.value = new Boolean(v);
	}
	
	public JsonArrayElement(AbstractCompositeJson v) {
		this.value = v;
	}
	
	public JsonArrayElement() {
		//this.value = null;
		this.value = new String("null"); // so that when this element is printed, it prints 'null' rather
		                                 //   throw an Exception for trying to print a null object. 
	}
	
	/**
	 * toString() is overridden so that it just returns the
	 * String representation of value.
	 */
	public String toString() {
		return value.toString();
	}
}
